import Vue from 'vue';
import Router from 'vue-router';
Vue.use(Router);

const router = new Router({
  routes: [
    {
      path: '/login',
      name: 'login',
      component: () => import('@/components/login')
    },
    {
      path: '/revisePwd',
      name: 'revisePwd',
      component: () => import('@/components/revisePwd')
    },
    {
      path: '/',
      name: 'index',
      component: () => import('@/components/index'),
      children: [
        {
          path: '/index',
          name: 'index',
          component: () => import('@/components/index/index.vue')
        },
        {
          path: '/myCourse',
          name: 'myCourse',
          component: () => import('@/components/myCourse/index.vue')
        },
        {
          path: '/courseDetail',
          name: 'courseDetail',
          component: () => import('@/components/courseDetail/index.vue')
        },
        {
          path: '/courseCatalogue',
          name: 'courseCatalogue',
          component: () => import('@/components/courseCatalogue/index.vue')
        },
        {
          path: '/course/:type',
          name: 'course',
          meta: { name: '课程列表' },
          component: () => import('@/components/courseList/index')
        },
        {
          path: '/searchList',
          name: 'searchList',
          meta: { name: '搜索列表' },
          component: () => import('@/components/searchList/index')
        },
        {
          path: '/myCollect',
          name: 'myCollect',
          meta: { name: '我的收藏' },
          component: () => import('@/components/myCollect/index')
        },
        {
          path: '/myTraining',
          name: 'myTraining',
          meta: { name: '我的培训' },
          component: () => import('@/components/myTraining/index')
        },
        {
          path: '/myStudy',
          name: 'myStudy',
          meta: { name: '我的学习' },
          component: () => import('@/components/myStudy/index')
        },
        {
          path: '/app/my',
          name: 'appMy',
          meta: { name: 'app我的页面' },
          component: () => import('@/components/app/my/index')
        },
        {
          path: '/message',
          name: 'message',
          meta: { name: '消息列表' },
          component: () => import('@/components/message/index')
        },
        {
          path: '/representative',
          name: 'representative',
          meta: { name: '新农人代表' },
          component: () => import('@/components/representative/index')
        }
      ]
    },
    {
      path: '/svg',
      name: 'svg',
      component: () => import('@/components/svg-preview')
    },
  ]
});

const originalPush = Router.prototype.push;
const originalReplace = Router.prototype.replace;
//push
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject);
  return originalPush.call(this, location).catch(err => err);
};
//replace
Router.prototype.replace = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalReplace.call(this, location, onResolve, onReject);
  return originalReplace.call(this, location).catch(err => err);
};

export default router;
